<template>
	<view class="content">
		<image :src="src"  mode="widthFix"></image>
		<view class="clo-444 f34 tac">{{text}}</view>
		<button class="bbg" @click="back()">返回</button>
	</view>
</template>

<script>
	import {scanBind} from '@/utils/api'
	export default {
		data() {
			
			return {
				src:'',
				yes_src:'/static/icon6.png',
				no_src:'/static/nobind.png',
				text:''
			}
		},
		
		onLoad(e) {
			let q = decodeURIComponent(e.q)
			let info=q.split('?')[1].split('&');
			console.log(info)
			var user_id=info[0].split('=')[1]
			var type=info[1].split('=')[1]
			// console.log(user_id,type)
			// // var user_id=arr[1].split('=')[1]
			// return;

			uni.getProvider({service: 'oauth'}).then(res=>{
					this.provider=res.provider[0]
					uni.login({
						provider:this.provider
					}).then(loginRes=>{
						// console.log(loginRes,'看一下授权登录信息')
						var data={'code':loginRes.code,'provider':this.provider,'action':'bind','user_id':user_id,'type':type,'from':'weixin'}
						scanBind(data).then(res=>{
							let data=res.data
							uni.setStorageSync('token',data.access_token)
							this.src=this.yes_src
							this.text='绑定成功'
							// this.getInfo()
						}).catch(err=>{
							console.log(err)
							this.src=this.no_src
							this.text='绑定失败'
						})
					})
			})	
			// console.log(user_id)

		},
		methods: {
			back(){
				uni.reLaunch({
					url:'/pages/index/index'
				})
			}
		}
	}
</script>

<style>
	image{width: 50%; margin: 80rpx 25% 40rpx 25%;}
	
	.bbg {width: 80%; margin: 40rpx 10%;}
</style>
